home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.alaska-software.com
/
2014.06.ftp.alaska-software.com.tar
/
ftp.alaska-software.com
/
3pp
/
mxsetup.old
/
{app}
/
ListProg.prg
< prev
next >
Wrap
Text File
|
2001-09-14
|
14KB
|
479 lines
***********************************************************************
* MxListProg.PRG
***********************************************************************
* Created 12/23/1999 - jpc
* Prints a user specified ASCII file to the Printer with Line Numbers.
***********************************************************************
#include "Xbp.ch"
#include "Font.ch"
#include "Common.ch"
#include "Appevent.ch"
#include "Gra.ch"
#include "Directry.ch"
#define xbeUser_DateMarked xbeP_User + 1
#define xbeUser_Print xbeP_User + 2
#define xbeUser_Browse xbeP_User + 3
PROCEDURE MxListProg()
LOCAL oDlg, mp1, mp2, oFocus:=setAppfocus(), oWin, oPrinterPS, oXbp, oXbpp
LOCAL cFileName, lExit := .F., aFiles := {}, i, aDates := {}, aSize := {}, aPos := {}
LOCAL cFile := "", cOldfile := "", cDir := "C:\", aFileNames := {}
PRIVATE lUpdate := .F.
if alltrim(upper(procName(1)))=="MAIN"
cDir := CurDrive()+":\"+CurDir()
endif
aSize := setAppWindow():currentSize()
aPos := setAppWindow():currentPos()
oDlg := XbpDialog():new(AppDeskTop(),SetAppWindow():drawingArea,{aPos[1]+5,aPos[2]+(aSize[2]-170)},{aSize[1]-10,130})
oDlg:tasklist := .F.
oDlg:title := "Print Text Files with Line Numbers - If WildCards are in [File Name], [Modified Since] will be used to Validate"
oDlg:close := {|| lExit := .T. }
oDlg:border := XBPDLG_RAISEDBORDERTHIN_FIXED
oDlg:SetFontCompoundName("9.Arial Bold")
oDlg:create()
oFocus := SetAppFocus( oDlg )
oDlg:setModalState(XBP_DISP_APPMODAL)
oXbp := XbpStatic():new()
oXbp:caption := "Print File(s):"
oXbp:options := XBPSTATIC_TEXT_VCENTER
oXbp:create( oDlg:drawingarea, , {10,70}, {95,20} )
oXbp1 := XbpSle():new()
oXbp1:dataLink := {|x| IIf( x==NIL , "" , cFileName := x ) }
oXbp1:clipSiblings := .T.
oXbp1:bufferlength := 250
oXbp1:border := .T.
oXbp1:tabstop := .F.
oXbp1:editable := .T.
oXbp1:create( oDlg:drawingarea, , {105,70}, {aSize[1]-135,20} )
oXbp1:setdata(cFile)
oXbp1:setname(1)
oXbp1:helpLink := ToolHelpLabel():new()
oXbp1:cargo := procname()+"1"
cDirectry := oXbp1:editbuffer()
oXbp1:setMarked( {oXbp1:bufferlength,oXbp1:bufferlength} )
oXbp := XbpStatic():new()
oXbp:caption := "Modified Since:"
oXbp:options := XBPSTATIC_TEXT_VCENTER
oXbp:create( oDlg:drawingarea, , {10,40}, {95,20} )
for i := 365 to 1 step -1
aAdd(aDates,dtoc(date()+1-i))
next i
oDateBox := XbpComboBox():new()
oDateBox:clipSiblings := .F.
oDateBox:type := XBPCOMBO_DROPDOWNLIST
oDateBox:Markmode := XBPLISTBOX_MM_SINGLE
oDateBox:SetFontCompoundName("8.Arial Bold")
oDateBox:datalink := {|x| IIf( x==NIL, {nDate}, nDate := x[1] )}
oDateBox:create(oDlg:drawingarea , , {105,-340}, {80,400} )
oDateBox:setname(2)
oDateBox:helpLink := ToolHelpLabel():new()
oDateBox:cargo := procname()+"2"
AEval(aDates, {|c| oDateBox:addItem(c)} )
nDate := len(aDates)-1
oDateBox:itemMarked := {|mp1,mp2,obj| ;
mp1 := obj:getdata()[1],1,;
PostAppEvent( xbeUser_DateMarked,mp1 ) }
oDateBox:setData()
oDateBox:show()
oXbp := XbpCheckbox():new()
oXbp:caption := "Update File"
oXbp:create(oDlg:drawingArea , , {250,40}, {100,20} )
oXbp:selected := {| mp1, mp2, oChk| lUpdate := mp1}
oXbp:setdata(lUpDate)
oXbp:setname(1)
oXbp := XBPPushButton():new( oDlg:drawingArea, , {aSize[1]-200,10}, {80,24}, { { XBP_PP_COMPOUNDNAME, "10.Alaska CRT" } } )
oXbp:caption := "Browse"
oXbp:clipSiblings := .T.
oXbp:create()
oXbp:activate := { || PostAppEvent(xbeUser_Browse) }
oXbpp := XBPPushButton():new( oDlg:drawingArea, , {aSize[1]-110,10}, {80,24}, { { XBP_PP_COMPOUNDNAME, "10.Alaska CRT" } } )
oXbpp:caption := "Print"
oXbpp:clipSiblings := .T.
oXbpp:create()
oXbpp:activate := { || PostAppEvent(xbeUser_Print) }
setAppFocus(oXbpp)
oDlg:show()
do while !lExit
if empty(aFileNames)
oDlg:disable()
oFiles := FileDialog():new()
oFiles:fileMustExist := .T.
oFiles:center := .F.
oFiles:title := "Select a File"
oFiles:filter := { { "Program Files (*.PRG)", "*.PRG" },;
{ "Project Files (*.XPJ)", "*.XPJ" },;
{ "Text Files (*.TXT)", "*.TXT" },;
{ "All Files (*.*)", "*.*" } }
oFiles:startPath := cDir
oFiles:allowMultiSelect := .T.
oFiles:create(,,{aPos[1]+110,aPos[2]+(aSize[2]-430)})
aFileNames := oFiles:aFileNames
SetAppFocus(oDlg)
oDlg:enable()
SetAppFocus(oXbpp)
endif
if !empty(aFileNames)
for i:=1 to len(aFileNames)
if i==1
cFile := aFileNames[1]
else
cFile := cFile+right(aFileNames[i],len(aFileNames[i])-rat("\",aFileNames[1]))
endif
if i<len(aFileNames)
cFile := cFile+","
endif
next i
else
lExit := .T.
loop
endif
if cOldFile<>cFile
oXbp1:setdata(cFile)
endif
cOldFile := cFile
nEvent := AppEvent( @mp1, @mp2, @oXbp )
if nEvent == xbeP_Keyboard .and. mp1 == xbeK_ESC
oXbp:handleEvent( nEvent, mp1, mp2 )
lExit := .T.
loop
elseif nEvent == xbeUser_Print
cFileName := alltrim(oXbp1:editbuffer())
if right(cFilename,1)='\'
elseif !file(cFilename).and.at('.',cFilename)=0
cFilename := cFilename+'.prg'
endif
if right(cFilename,1)=='\'
cDirectry := cFileName
aFiles := directory(cFileName+'*.prg')
oXbp1:setdata(cFileName+"*.prg")
dStartdate := ctod(oDateBox:XbpSLE:editbuffer())
for i=1 to len(aFiles)
if aFiles[i,F_DATE]>=dStartdate
aAdd(aFileNames,upper(cDirectry)+alltrim(aFiles[i,F_NAME]))
endif
next i
oXbp1:setdata(cDirectry)
oXbp1:setMarked( {oXbp1:bufferlength,oXbp1:bufferlength} )
setAppFocus(oXbp1)
elseif "*"$cFilename.or."?"$cFileName
cDirectry := left(cFileName,rat("\",cFileName))
cDir := cDirectry
aFiles := directory(cFileName)
dStartdate := ctod(oDateBox:XbpSLE:editbuffer())
for i=1 to len(aFiles)
if aFiles[i,F_DATE]>=dStartdate
aAdd(aFileNames,upper(cDirectry)+alltrim(aFiles[i,F_NAME]))
endif
next i
oXbp1:setdata(cDirectry)
oXbp1:setMarked( {oXbp1:bufferlength,oXbp1:bufferlength} )
setAppFocus(oXbp1)
endif
if !empty(aFileNames)
oPrinterPS := PrinterPS()
for i:=1 to len(aFileNames)
ListFile(aFileNames[i],oPrinterPS)
next i
if oPrinterPS<>Nil
oPrinterPS:destroy()
endif
cDir := left(aFileNames[1],rat("\",aFileNames[1]))
cFile := ""
aSize(aFileNames,0)
endif
elseif nEvent == xbeUser_Browse
cFile := aFileNames[1]
cDir := left(cFile,rat("\",cFile))
cfile := ""
aSize(aFileNames,0)
endif
oXbp:handleEvent( nEvent, mp1, mp2 )
enddo
oDlg:destroy()
setAppFocus(oFocus)
RETURN
FUNCTION ListFile(cFilename,oPrinterPS)
LOCAL cString := cString2 := "", cSearch := " ,+)}|\"
LOCAL nX, nY, cHeader, nMaxLen := 132, aAttr, aFiles, i, n:=1, oFontDlg, oFont, oFontBig
LOCAL nIndent, nDifference, lContinue := .F., nColor := GRA_CLR_BLACK
if oPrinterPS==Nil
RETURN .F.
endif
cString := memoread(cFileName)
for i:=1 to 100
if substr(cString,i,1)$"`1234567890-=~!@#$%^&*()_+,./<>?;':[]\{}|"
*** OK ***
elseif substr(upper(cString),i,1)$"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
*** OK ***
elseif substr(cString,i,1)$chr(9)+chr(10)+chr(32)+chr(34)+chr(13)
*** OK ***
else
MsgBox("Invalid Character detected in "+cFileName+chr(13)+str(asc(substr(cString,i,1))))
RETURN .F.
endif
next i
nIndent := 5
do while len(cString)>2
nLen := at(chr(13),cString)
cPrintstr := rtrim(left(cString,nLen-1))
nDifference := len(cPrintStr)-len(alltrim(cPrintStr))
if nDifference>1.and.nDifference<nIndent
nIndent := nDifference
endif
cString := right(cString,len(cString)-(nLen+1))
enddo
cString := memoread(cFileName)
aAttr := ARRAY( GRA_AS_COUNT )
aFiles := directory(cFilename)
aPaperSize := oPrinterPS:device():paperSize()
nWidth := aPaperSize[1] // Actual Width of Paper
nHeight := aPaperSize[2] // Actual Height of Paper
nSide := aPaperSize[3] // Left & Right Margins
nTopBottom := aPaperSize[4] // Top & Bottom Margins
nLeft := 0
nBottom := 0
nRight := nWidth-(nSide*2)-2
nTop := nHeight-(nTopBottom*2)
oPrinterPS:device():startDoc()
oFontBig := XbpFont():new(oPrinterPS)
oFontBig:create("16.Times New Roman Bold")
oFont := NIL
if empty(oFont)
oFont := XbpFont():new(oPrinterPS)
oFont:create("8.Courier New")
endif
GraSetFont(oPrinterPS,oFont)
nX := 0
nY := 2500
ln := 0
nLen := 1
nPage := 1
do while len(cString)>2 //.and.nLen>0
if nY==2500
GraSetFont(oPrinterPS,oFontBig)
GraSetColor(oPrinterPS,GRA_CLR_DARKRED)
aAttr [ GRA_AS_HORIZALIGN ] := GRA_HALIGN_CENTER
GraSetAttrString(oPrinterPS,aAttr)
GraStringAt(oPrinterPS,{1000,nY},upper(cFileName))
oFont:configure("10."+oFont:compoundName+" Bold")
GraSetFont(oPrinterPS,oFont)
GraStringAt(oPrinterPS,{1000,nY-50},"Last Modified on "+dtoc(aFiles[1,F_DATE])+" at "+aFiles[1,F_TIME])
GraStringAt(oPrinterPS,{1000,nY-90},"Printed on "+dtoc(date())+" at "+time())
nY := nY-120
GraSetColor(oPrinterPS,GRA_CLR_BLACK)
aAttr [ GRA_AS_HORIZALIGN ] := GRA_HALIGN_LEFT
GraSetAttrString(oPrinterPS,aAttr)
endif
GraSetColor(oPrinterPS,GRA_CLR_BLACK)
ln := ln+1
nY := nY-40
if nY<100
oFont:configure("10."+oFont:compoundName+" Bold")
GraSetFont(oPrinterPS,oFont)
GraSetColor(oPrinterPS,GRA_CLR_DARKRED)
GraStringAt(oPrinterPS,{nX,nY-40},padc('Page '+alltrim(str(nPage)),100))
nY := 2500
oPrinterPS:device():newpage()
nPage := nPage+1
loop
endif
nLen := at(chr(13),cString)
cPrintstr := rtrim(left(cString,nLen-1))
nSp := 0
do while left(cPrintStr,1)==" ".or.left(cPrintStr,1)==chr(9)
if left(cPrintStr,1)==" "
nSp := nSp+1
else
nSp := nSp+nIndent
endif
cPrintStr := right(cPrintStr,len(cPrintStr)-1)
enddo
nSp := round((nSp/nIndent),0)*5
if nSp>90
nSp := 30
endif
cLeftStr := space(nSp)
cRightStr := alltrim(cPrintstr)
if cRightStr == replicate(left(cRightStr,1),len(cRightStr)).and.(nSp+len(cRightStr))>75
cRightStr := replicate(left(cRightStr,1),75-nSp)
endif
cPrintstr := cLeftStr+cRightStr
cPrintStr := StrTran( cPrintStr,chr(9)," " )
cString2 := cString2+replicate(chr(9),nSp/nIndent)+cRightStr+chr(13)+chr(10)
if oFont:nominalPointSize<>8
oFont:configure("8."+oFont:compoundName+" Bold")
GraSetFont(oPrinterPS,oFont)
GraSetColor(oPrinterPS,GRA_CLR_BLACK)
endif
GraStringAt(oPrinterPS,{nX+100,nY},str(ln,5))
if !empty(left(cPrintStr,1)).and.len(cPrintStr)<=75
oFont:configure("10."+oFont:compoundName+" Bold")
GraSetFont(oPrinterPS,oFont)
elseif oFont:nominalPointSize<>8
oFont:configure("8."+oFont:compoundName)
GraSetFont(oPrinterPS,oFont)
endif
cCheckStr :=upper(left(alltrim(cPrintStr),5))
if left(cCheckStr,1)$"*/".and.!lContinue
GraSetColor(oPrinterPS,GRA_CLR_DARKGREEN)
elseif left(cCheckStr,1)=="#".and.!lContinue
GraSetColor(oPrinterPS,GRA_CLR_BLUE)
elseif cCheckStr$"PROCEDURE|FUNCTION|RETURN|STATIC|INLINE|CLASS|ENDCLASS".and.!lContinue
GraSetColor(oPrinterPS,GRA_CLR_RED)
elseif (left(cCheckStr,2)=="IF".or.cCheckStr$"ENDIF|DO CASE|ENDCASE|DO WHILE|ENDDO").and.!lContinue
GraSetColor(oPrinterPS,GRA_CLR_DARKBLUE)
elseif cCheckStr$"LOCAL|PRIVATE|PUBLIC".and.!lContinue
GraSetColor(oPrinterPS,GRA_CLR_GREEN)
elseif !lContinue
GraSetColor(oPrinterPS,GRA_CLR_BLACK)
elseif lContinue
GraSetcolor(oPrinterPS,nColor)
endif
cCheckStr := upper(left(cPrintStr,5))
if cCheckStr$"METHOD".and.!lContinue
GraSetColor(oPrinterPS,GRA_CLR_RED)
endif
cPrintStr := alltrim(cPrintStr)
nLength := 0
do while nSp+len(cPrintstr)>93
for i := 1 to len(cSearch)
nSpace := rat(substr(cSearch,i,1),left(cPrintstr,93-nSp))
if nSpace<>0
i:=len(cSearch)
endif
next i
if nSpace==0
nSpace := 93-nSp
endif
if oFont:nominalPointSize<>8
oFont:configure("8."+oFont:compoundName+" Bold")
GraSetFont(oPrinterPS,oFont)
endif
GraStringAt(oPrinterPS,{nX+100,nY},space(8+nSp)+alltrim(left(cPrintstr,nSpace))+" ;")
nY := nY-40
cPrintStr := alltrim(right(cPrintStr,len(cPrintStr)-nSpace))
if nSp+len(cPrintStr)<=90
cPrintStr := space(3)+alltrim(cPrintStr)
endif
enddo
if !empty(cPrintStr)
if upper(left(alltrim(cPrintStr),4))$"ELSE|CASE"
cPrintStr := space(2)+cPrintStr
endif
GraStringAt(oPrinterPS,{nX+100,nY},space(8+nSp)+cPrintStr)
endif
if right(cPrintStr,1)==";"
lContinue := .T.
nColor := GraSetColor(oPrinterPS)[1]
else
lContinue := .F.
endif
cString := right(cString,len(cString)-(nLen+1))
enddo
if lUpDate
MemoWrit(cFileName,cString2)
endif
do while nY>=100
nY := nY-40
enddo
oFont:configure("10."+oFont:compoundName+" Bold")
GraSetFont(oPrinterPS,oFont)
GraSetColor(oPrinterPS,GRA_CLR_DARKRED)
GraStringAt(oPrinterPS,{nX,nY-40},padc('Page '+alltrim(str(nPage)),100))
oPrinterPS:device():endDoc()
RETURN .T.
FUNCTION SelectFont(oPS,cTitle,cDefaultFont)
LOCAL oFont, oFontDlg
LOCAL oCrt, oWin := setAppWindow(), oFocus := setAppFocus()
DEFAULT cTitle to "View Fonts"
DEFAULT cDefaultFont to "Arial"
oCrt := XbpCrt():new( , , {0,0}, 25, 80, "")
oCrt:clipChildren := .F.
oCrt:create()
SetAppWindow( oCrt )
// Create XbpFontDialog object
oFontDlg := XbpFontDialog():new(,,,oPS)
oFontDlg:familyName := cDefaultFont
oFontDlg:title := cTitle
oFontDlg:create() // Request font dialog
// Allow font to be selected
// using modal operation
oFont := oFontDlg:display( XBP_DISP_APPMODAL )
oFontDlg:destroy( ) // Destroy font dialog
oCrt:destroy()
setAppWindow( oWin )
setAppFocus( oFocus )
RETURN oFont
STATIC FUNCTION PrinterPS()
LOCAL oPS := Nil
LOCAL oDC := SetPrinter(.T.,,,.T.)
LOCAL oFocus := setAppFocus()
if oDC<>Nil
oPS:=XbpPresSpace():new()
oPS:Create( oDC, {oDC:paperSize()[1],oDC:paperSize()[2]}, GRA_PU_LOMETRIC )
endif
setAppFocus(oFocus)
RETURN oPS